
/**
 @file sys_usw_serdes_api.c

 @date 2023-10-08
 
 @version v1.0

 The file define APIs of SerDes in sys layer
*/
/****************************************************************************
 *
 * Header Files
 *
 ****************************************************************************/
#include "ctc_error.h"
#include "sys_usw_common.h"
#include "sys_usw_mac.h"
#include "sys_usw_datapath.h"
#include "sys_usw_dmps.h"
#include "sys_usw_dmps_db.h"
#include "sys_usw_serdes_api.h"
#include "drv_api.h"
#include "sys_usw_mcu.h"
#include "usw/include/drv_common.h"

/****************************************************************************
 *
 * Global and static variables
 *
 *****************************************************************************/

/****************************************************************************
 *
 * Functions
 *
 *****************************************************************************/

/*
[Func desc]        Set group initialization
[IN param]         uint8 lchip: Lchip ID
                   uint16 grp: Group ID
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_group_init(uint8 lchip, uint16 grp)
{
    MCHIP_SERDES_CB(serdes_set_group_init, lchip, grp);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane initialization
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_lane_init(uint8 lchip, uint16 serdes)
{
    MCHIP_SERDES_CB(serdes_set_lane_init, lchip, serdes);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane speed
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
                   uint8 spd: lane speed, refers to sys_dmps_serdes_speed_t
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_lane_speed(uint8 lchip, uint16 serdes, uint8 dir, uint8 spd)
{
    MCHIP_SERDES_CB(serdes_set_lane_speed, lchip, serdes, dir, spd);
    return CTC_E_NONE;
}

/*
[Func desc]        Set group speed
[IN param]         uint8 lchip: Lchip ID
                   uint16 grp: Group ID
                   uint8 grp_spd: group speed
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_group_speed(uint8 lchip, uint16 grp, uint8 grp_spd)
{
    MCHIP_SERDES_CB(serdes_set_group_speed, lchip, grp, grp_spd);
    return CTC_E_NONE;
}

/*
[Func desc]        Firmware load per-lane
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   void* p_fw: firmware data
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_lane_fw_load(uint8 lchip, uint16 serdes, void* p_fw)
{
    MCHIP_SERDES_CB(serdes_set_lane_fw_load, lchip, serdes, p_fw);
    return CTC_E_NONE;
}

/*
[Func desc]        Firmware load per-group
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   void* p_fw: firmware data
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_group_fw_load(uint8 lchip, uint16 grp, void* p_fw)
{
    MCHIP_SERDES_CB(serdes_set_group_fw_load, lchip, grp, p_fw);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane power on/off
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
                   uint8 pw_up: power on/off, 1 - on, 0 - off
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_lane_power(uint8 lchip, uint16 serdes, uint8 dir, uint8 pw_up)
{
    MCHIP_SERDES_CB(serdes_set_lane_power, lchip, serdes, dir, pw_up);
    return CTC_E_NONE;
}

/*
[Func desc]        Set group power on/off
[IN param]         uint8 lchip: Lchip ID
                   uint16 grp: Group ID
                   uint8 pw_up: power on/off, 1 - on, 0 - off
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_group_power(uint8 lchip, uint16 grp, uint8 pw_up)
{
    MCHIP_SERDES_CB(serdes_set_group_power, lchip, grp, pw_up);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane signal enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_EN
*/
int32 sys_usw_dmps_serdes_set_lane_en(uint8 lchip, uint16 serdes, uint8 dir, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_lane_en, lchip, serdes, dir, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane reset
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
                   uint8 rst_level: reset level, refers to IP details
                   uint8 rst_val: reset value, 0 - release, 1 - reset, 2 - reset then release
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_RESET
*/
int32 sys_usw_dmps_serdes_set_lane_rst(uint8 lchip, uint16 serdes, uint8 dir, uint8 rst_level, uint8 rst_val)
{
    MCHIP_SERDES_CB(serdes_set_lane_rst, lchip, serdes, dir, rst_level, rst_val);
    return CTC_E_NONE;
}

/*
[Func desc]        Set RX signal detect force mode
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 fc_up: force signal detect, 1 - sigdet up, 0 - sigdet down
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_rx_force_sigdet(uint8 lchip, uint16 serdes, uint8 fc_up)
{
    MCHIP_SERDES_CB(serdes_set_rx_force_sigdet, lchip, serdes, fc_up);
    return CTC_E_NONE;
}

/*
[Func desc]        Set RX signal detect threshold
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 thrd_mv: threshold(mV)
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_rx_sigdet_thrd(uint8 lchip, uint16 serdes, uint8 thrd_mv)
{
    MCHIP_SERDES_CB(serdes_set_rx_sigdet_thrd, lchip, serdes, thrd_mv);
    return CTC_E_NONE;
}

/*
[Func desc]        Set TX equalizer force mode
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   ctc_chip_serdes_ffe_t* p_ffe: FFE values
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_FFE
*/
int32 sys_usw_dmps_serdes_set_tx_eq_force(uint8 lchip, uint16 serdes, void* p_ffe)
{
    MCHIP_SERDES_CB(serdes_set_tx_eq_force, lchip, serdes, p_ffe);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane PRBS test pattern
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
                   uint8 pattern: test pattern, refers to sys_dmps_serdes_test_pattern_t
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_PRBS
*/
int32 sys_usw_dmps_serdes_set_lane_prbs_test_pattern(uint8 lchip, uint16 serdes, uint8 dir, uint8 pattern)
{
    MCHIP_SERDES_CB(serdes_set_lane_prbs_test_pattern, lchip, serdes, dir, pattern);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane PRBS test enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_PRBS
*/
int32 sys_usw_dmps_serdes_set_lane_prbs_test_en(uint8 lchip, uint16 serdes, uint8 dir, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_lane_prbs_test_en, lchip, serdes, dir, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane PRBS test reset
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_PRBS
*/
int32 sys_usw_dmps_serdes_set_lane_prbs_test_rst(uint8 lchip, uint16 serdes)
{
    MCHIP_SERDES_CB(serdes_set_lane_prbs_test_rst, lchip, serdes);
    return CTC_E_NONE;
}

/*
[Func desc]        Run a PRBS test
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint32 duration_ms: time duration(ms)
[OUT param]        ctc_chip_serdes_prbs_t *p_prbs: PRBS test counter result
[CTC API]          CTC_CHIP_PROP_SERDES_PRBS
*/
int32 sys_usw_dmps_serdes_set_lane_prbs_test_run(uint8 lchip, uint16 serdes, uint32 duration_ms, void* p_prbs)
{
    MCHIP_SERDES_CB(serdes_set_lane_prbs_test_run, lchip, serdes, duration_ms, p_prbs);
    return CTC_E_NONE;
}

/*
[Func desc]        Set RX CTLE force mode value
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   ctc_chip_serdes_ctle_t* p_ctle: CTLE values
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_DFE
*/
int32 sys_usw_dmps_serdes_set_rx_ctle_force(uint8 lchip, uint16 serdes, void* p_ctle)
{
    MCHIP_SERDES_CB(serdes_set_rx_ctle_force, lchip, serdes, p_ctle);
    return CTC_E_NONE;
}

/*
[Func desc]        Set RX DFE force mode value
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint32 dfe[]: DFE values
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_rx_dfe_force(uint8 lchip, uint16 serdes, uint32* dfe)
{
    MCHIP_SERDES_CB(serdes_set_rx_dfe_force, lchip, serdes, dfe);
    return CTC_E_NONE;
}

/*
[Func desc]        Set RX FFE force mode value
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint32 ffe_rx[]: rx ffe values
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_rx_ffe_force(uint8 lchip, uint16 serdes, uint32* ffe_rx)
{
    MCHIP_SERDES_CB(serdes_set_rx_ffe_force, lchip, serdes, ffe_rx);
    return CTC_E_NONE;
}

/*
[Func desc]        Set RX CTLE enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_DFE
*/
int32 sys_usw_dmps_serdes_set_rx_ctle_en(uint8 lchip, uint16 serdes, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_rx_ctle_en, lchip, serdes, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Set RX DFE enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_DFE
*/
int32 sys_usw_dmps_serdes_set_rx_dfe_en(uint8 lchip, uint16 serdes, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_rx_dfe_en, lchip, serdes, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Set RX FFE enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_rx_ffe_en(uint8 lchip, uint16 serdes, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_rx_ffe_en, lchip, serdes, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane loopback
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   ctc_chip_serdes_loopback_t* p_lpbk: loopback type and enable/disable
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_LOOPBACK
*/
int32 sys_usw_dmps_serdes_set_lane_loopback(uint8 lchip, uint16 serdes, void* p_lpbk)
{
    MCHIP_SERDES_CB(serdes_set_lane_loopback, lchip, serdes, p_lpbk);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane polarity
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
                   uint8 pol: polarity, refers to sys_dmps_serdes_polarity_t
[OUT param]        None
[CTC API]          CTC_CHIP_PEOP_SERDES_POLARITY
*/
int32 sys_usw_dmps_serdes_set_lane_polarity(uint8 lchip, uint16 serdes, uint8 dir, uint8 pol)
{
    MCHIP_SERDES_CB(serdes_set_lane_polarity, lchip, serdes, dir, pol);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane error injection
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 err_num: error bit number
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_lane_err_inj(uint8 lchip, uint16 serdes, uint8 err_num)
{
    MCHIP_SERDES_CB(serdes_set_lane_err_inj, lchip, serdes, err_num);
    return CTC_E_NONE;
}

/*
[Func desc]        Set RX training enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_rx_train_en(uint8 lchip, uint16 serdes, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_rx_train_en, lchip, serdes, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Set TX training enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_tx_train_en(uint8 lchip, uint16 serdes, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_tx_train_en, lchip, serdes, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Set RX cdr det enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_rx_cdr_det_en(uint8 lchip, uint16 serdes, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_rx_cdr_det_en, lchip, serdes, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane precode
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_PRE_CODING
*/
int32 sys_usw_dmps_serdes_set_lane_precode(uint8 lchip, uint16 serdes, uint8 dir, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_lane_precode, lchip, serdes, dir, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane graycode
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_lane_graycode(uint8 lchip, uint16 serdes, uint8 dir, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_lane_graycode, lchip, serdes, dir, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane MSB/LSB
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
                   uint8 value: msb or lsb, 1 or 0
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_lane_msblsb(uint8 lchip, uint16 serdes, uint8 dir, uint8 value)
{
    MCHIP_SERDES_CB(serdes_set_lane_msblsb, lchip, serdes, dir, value);
    return CTC_E_NONE;
}

/*
[Func desc]        Set group register
[IN param]         uint8 lchip: Lchip ID
                   uint16 grp: Group ID
                   uint32 addr: register address
                   uint32 mask: register mask, bit value 1 means ignore, 0 means use
                   uint32 data: data to be written
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_group_reg(uint8 lchip, uint16 grp, uint32 addr, uint32 mask, uint32 data)
{
    MCHIP_SERDES_CB(serdes_set_group_reg, lchip, grp, addr, mask, data);
    return CTC_E_NONE;
}

/*
[Func desc]        Set lane register
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint32 addr: register address
                   uint32 mask: register mask, bit value 1 means ignore, 0 means use
                   uint32 data: data to be written
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_lane_reg(uint8 lchip, uint16 serdes, uint32 addr, uint32 mask, uint32 data)
{
    MCHIP_SERDES_CB(serdes_set_lane_reg, lchip, serdes, addr, mask, data);
    return CTC_E_NONE;
}

/*
[Func desc]        Set Firmware command
[IN param]         uint8 lchip: Lchip ID
                   uint16 fw_id: for per-lane firmware it means serdes id; for per-group firmware it means group id
                   void* fw_cmd: firmware command structure, refers to IP details
[OUT param]        None
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_set_fw_cmd(uint8 lchip, uint16 fw_id, void* fw_cmd)
{
    MCHIP_SERDES_CB(serdes_set_fw_cmd, lchip, fw_id, fw_cmd);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane speed
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_spd: lane speed, refers to sys_dmps_serdes_speed_t
[CTC API]          CTC_CHIP_PROP_SERDES_ID_TO_GPORT
*/
int32 sys_usw_dmps_serdes_get_lane_speed(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_spd)
{
    MCHIP_SERDES_CB(serdes_get_lane_speed, lchip, serdes, dir, p_spd);
    return CTC_E_NONE;
}

/*
[Func desc]        Get firmware version per-lane
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        sys_usw_dmps_serdes_fw_version_t* p_fw_ver: current firmware version
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_lane_fw_version(uint8 lchip, uint16 serdes, void* p_fw_ver)
{
    MCHIP_SERDES_CB(serdes_get_lane_fw_version, lchip, serdes, p_fw_ver);
    return CTC_E_NONE;
}

/*
[Func desc]        Get firmware version per-group
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        sys_usw_dmps_serdes_fw_version_t* p_fw_ver: current firmware version
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_group_fw_version(uint8 lchip, uint16 grp, void* p_fw_ver)
{
    MCHIP_SERDES_CB(serdes_get_group_fw_version, lchip, grp, p_fw_ver);
    return CTC_E_NONE;
}

/*
[Func desc]        Get firmware running status per-lane
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_stat: firmware running status, 1 - running, 0 - stop
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_lane_fw_stat(uint8 lchip, uint16 serdes, uint8* p_stat)
{
    MCHIP_SERDES_CB(serdes_get_lane_fw_stat, lchip, serdes, p_stat);
    return CTC_E_NONE;
}

/*
[Func desc]        Get firmware running status per-group
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_stat: firmware running status, 1 - running, 0 - stop
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_group_fw_stat(uint8 lchip, uint16 serdes, uint8* p_stat)
{
    MCHIP_SERDES_CB(serdes_get_group_fw_stat, lchip, serdes, p_stat);
    return CTC_E_NONE;
}

/*
[Func desc]        Get group PLL lock
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_pll_lock: pll lock status, 1 - lock, 0 - unlock
[CTC API]          CTC_CHIP_PROP_PLL_LOCK_STATUS
*/
int32 sys_usw_dmps_serdes_get_group_pll_lock(uint8 lchip, uint16 serdes, uint8* p_pll_lock)
{
    MCHIP_SERDES_CB(serdes_get_group_pll_lock, lchip, serdes, p_pll_lock);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane PLL lock
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_pll_lock: pll lock status, 1 - lock, 0 - unlock
[CTC API]          CTC_CHIP_PROP_PLL_LOCK_STATUS
*/
int32 sys_usw_dmps_serdes_get_lane_pll_lock(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_pll_lock)
{
    MCHIP_SERDES_CB(serdes_get_lane_pll_lock, lchip, serdes, dir, p_pll_lock);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX signal detect
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_sig_det: signal detect, 1 - up, 0 - down
[CTC API]          CTC_CHIP_PROP_SERDES_ID_TO_GPORT
*/
int32 sys_usw_dmps_serdes_get_rx_sigdet(uint8 lchip, uint16 serdes, uint8* p_sig_det)
{
    MCHIP_SERDES_CB(serdes_get_rx_sigdet, lchip, serdes, p_sig_det);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX signal detect thrd
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint32* p_thrd_mv: threshold(mV)
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_rx_sigdet_thrd(uint8 lchip, uint16 serdes, uint32* p_thrd_mv)
{
    MCHIP_SERDES_CB(serdes_get_rx_sigdet_thrd, lchip, serdes, p_thrd_mv);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX force mode signal detect
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_is_fc: is sigdet force or not, 1 - force, 0 - no force
                   uint8* p_sigdet: force sigdet value, 1 - up, 0 - down (if sigdet is not force then this value will always 0 invalid)
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_rx_force_sigdet(uint8 lchip, uint16 serdes, uint8* p_is_fc, uint8* p_sigdet)
{
    MCHIP_SERDES_CB(serdes_get_rx_force_sigdet, lchip, serdes, p_is_fc, p_sigdet);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX ready
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_rdy: ready status, 1 - rx is ready 0 - rx is still establishing
[CTC API]          CTC_CHIP_PROP_SERDES_ID_TO_GPORT
*/
int32 sys_usw_dmps_serdes_get_rx_ready(uint8 lchip, uint16 serdes, uint8* p_rdy)
{
    MCHIP_SERDES_CB(serdes_get_rx_ready, lchip, serdes, p_rdy);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane signal enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
[CTC API]          CTC_CHIP_PROP_SERDES_EN
*/
int32 sys_usw_dmps_serdes_get_lane_en(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_en)
{
    MCHIP_SERDES_CB(serdes_get_lane_en, lchip, serdes, dir, p_en);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane reset
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_rst: current reset reg value, 1 - reset, 0 - release (note this cannot be 2)
[CTC API]          CTC_CHIP_PROP_SERDES_RESET
*/
int32 sys_usw_dmps_serdes_get_lane_rst(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_rst)
{
    MCHIP_SERDES_CB(serdes_get_lane_rst, lchip, serdes, dir, p_rst);
    return CTC_E_NONE;
}

/*
[Func desc]        Get TX equalizer value
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        ctc_chip_serdes_ffe_t* p_ffe: current FFE values
[CTC API]          CTC_CHIP_PROP_SERDES_FFE
*/
int32 sys_usw_dmps_serdes_get_tx_eq(uint8 lchip, uint16 serdes, void* p_ffe)
{
    MCHIP_SERDES_CB(serdes_get_tx_eq, lchip, serdes, p_ffe);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane PRBS test pattern
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_pattern: test pattern, refers to sys_dmps_serdes_test_pattern_t
[CTC API]          CTC_CHIP_PROP_SERDES_PRBS
*/
int32 sys_usw_dmps_serdes_get_lane_prbs_test_pattern(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_pattern)
{
    MCHIP_SERDES_CB(serdes_get_lane_prbs_test_pattern, lchip, serdes, dir, p_pattern);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane PRBS test enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
[CTC API]          CTC_CHIP_PROP_SERDES_PRBS
*/
int32 sys_usw_dmps_serdes_get_lane_prbs_test_en(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_en)
{
    MCHIP_SERDES_CB(serdes_get_lane_prbs_test_en, lchip, serdes, dir, p_en);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane PRBS test counter
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        ctc_chip_serdes_prbs_t *p_prbs: PRBS test counter result
[CTC API]          CTC_CHIP_PROP_SERDES_PRBS
*/
int32 sys_usw_dmps_serdes_get_lane_prbs_test_cnt(uint8 lchip, uint16 serdes, void* p_prbs)
{
    MCHIP_SERDES_CB(serdes_get_lane_prbs_test_cnt, lchip, serdes, p_prbs);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX CTLE value
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        ctc_chip_serdes_ctle_t* p_ctle: current CTLE values
[CTC API]          CTC_CHIP_PROP_SERDES_CTLE
*/
int32 sys_usw_dmps_serdes_get_rx_ctle(uint8 lchip, uint16 serdes, void* p_ctle)
{
    MCHIP_SERDES_CB(serdes_get_rx_ctle, lchip, serdes, p_ctle);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX DFE value
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint32 dfe[]: current DFE values
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_rx_dfe(uint8 lchip, uint16 serdes, uint32* dfe)
{
    MCHIP_SERDES_CB(serdes_get_rx_dfe, lchip, serdes, dfe);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX FFE value
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint32 ffe_rx[]: current rx ffe values
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_rx_ffe(uint8 lchip, uint16 serdes, uint32* ffe_rx)
{
    MCHIP_SERDES_CB(serdes_get_rx_ffe, lchip, serdes, ffe_rx);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX CTLE enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
[CTC API]          CTC_CHIP_PROP_SERDES_DFE
*/
int32 sys_usw_dmps_serdes_get_rx_ctle_en(uint8 lchip, uint16 serdes, uint8* p_en)
{
    MCHIP_SERDES_CB(serdes_get_rx_ctle_en, lchip, serdes, p_en);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX DFE enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
[CTC API]          CTC_CHIP_PROP_SERDES_CTLE
*/
int32 sys_usw_dmps_serdes_get_rx_dfe_en(uint8 lchip, uint16 serdes, uint8* p_en)
{
    MCHIP_SERDES_CB(serdes_get_rx_dfe_en, lchip, serdes, p_en);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX FFE enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_rx_ffe_en(uint8 lchip, uint16 serdes, uint8* p_en)
{
    MCHIP_SERDES_CB(serdes_get_rx_ffe_en, lchip, serdes, p_en);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane loopback
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        ctc_chip_serdes_loopback_t* p_lpbk: current loopback type and enable/disable
[CTC API]          CTC_CHIP_PROP_SERDES_LOOPBACK
*/
int32 sys_usw_dmps_serdes_get_lane_loopback(uint8 lchip, uint16 serdes, void* p_lpbk)
{
    MCHIP_SERDES_CB(serdes_get_lane_loopback, lchip, serdes, p_lpbk);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane polarity
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_pol: polarity, refers to sys_dmps_serdes_polarity_t
[CTC API]          CTC_CHIP_PEOP_SERDES_POLARITY
*/
int32 sys_usw_dmps_serdes_get_lane_polarity(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_pol)
{
    MCHIP_SERDES_CB(serdes_get_lane_polarity, lchip, serdes, dir, p_pol);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane power
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_pw_up: power on/off, 1 - on, 0 - off
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_lane_power(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_pw_up)
{
    MCHIP_SERDES_CB(serdes_get_lane_power, lchip, serdes, dir, p_pw_up);
    return CTC_E_NONE;
}

/*
[Func desc]        Get group power
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_pw_up: power on/off, 1 - on, 0 - off
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_group_power(uint8 lchip, uint16 serdes, uint8* p_pw_up)
{
    MCHIP_SERDES_CB(serdes_get_group_power, lchip, serdes, p_pw_up);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX training status
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
                   uint8* p_stat: current training status, refers to sys_port_cl72_status_t
                   uint32* p_reason: detail information, like fail reason, refers to IP details
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_rx_train_stat(uint8 lchip, uint16 serdes, uint8* p_en, uint8* p_stat, uint32* p_reason)
{
    MCHIP_SERDES_CB(serdes_get_rx_train_stat, lchip, serdes, p_en, p_stat, p_reason);
    return CTC_E_NONE;
}

/*
[Func desc]        Get TX training status
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
                   uint8* p_stat: current training status, refers to sys_port_cl72_status_t
                   uint32* p_reason: detail information, like fail reason, refers to IP details
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_tx_train_stat(uint8 lchip, uint16 serdes, uint8* p_en, uint8* p_stat, uint32* p_reason)
{
    MCHIP_SERDES_CB(serdes_get_tx_train_stat, lchip, serdes, p_en, p_stat, p_reason);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX eye open
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 wh_sel: width / height select, refers to _sys_dmps_serdes_eye_t
[OUT param]        uint32* p_eo_margin: current eye open height / width
[CTC API]          CTC_CHIP_PROP_SERDES_EYE_DIAGRAM
*/
int32 sys_usw_dmps_serdes_get_rx_eye_open(uint8 lchip, uint16 serdes, uint8 wh_sel, uint32* p_eo_margin)
{
    MCHIP_SERDES_CB(serdes_get_rx_eye_open, lchip, serdes, wh_sel, p_eo_margin);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX eye plot
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint32* p_eye_data: current eye shape data
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_rx_eye_plot(uint8 lchip, uint16 serdes, uint32* p_eye_data)
{
    MCHIP_SERDES_CB(serdes_get_rx_eye_plot, lchip, serdes, p_eye_data);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX CDR detect enable
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_rx_cdr_det_en(uint8 lchip, uint16 serdes, uint8* p_en)
{
    MCHIP_SERDES_CB(serdes_get_rx_cdr_det_en, lchip, serdes, p_en);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX CDR lock
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_is_lock: current CDR lock status, 1 - lock, 0 - unlock
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_rx_cdr_lock(uint8 lchip, uint16 serdes, uint8* p_is_lock)
{
    MCHIP_SERDES_CB(serdes_get_rx_cdr_lock, lchip, serdes, p_is_lock);
    return CTC_E_NONE;
}

/*
[Func desc]        Get RX SNR
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint32* p_snr_db: current signal / noise ratio (dB*1000)
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_rx_snr(uint8 lchip, uint16 serdes, uint32* p_snr_db)
{
    MCHIP_SERDES_CB(serdes_get_rx_snr, lchip, serdes, p_snr_db);
    return CTC_E_NONE;
}

/*
[Func desc]        Read lane register
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint32 addr: register address
                   uint32 mask: register mask, bit value 1 means ignore, 0 means use
[OUT param]        uint32* p_data: read out data
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_lane_reg(uint8 lchip, uint16 serdes, uint32 addr, uint32 mask, uint32* p_data)
{
    MCHIP_SERDES_CB(serdes_get_lane_reg, lchip, serdes, addr, mask, p_data);
    return CTC_E_NONE;
}

/*
[Func desc]        Read group register
[IN param]         uint8 lchip: Lchip ID
                   uint16 grp: Group ID
                   uint32 addr: register address
                   uint32 mask: register mask, bit value 1 means ignore, 0 means use
[OUT param]        uint32* p_data: read out data
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_group_reg(uint8 lchip, uint16 grp, uint32 addr, uint32 mask, uint32* p_data)
{
    MCHIP_SERDES_CB(serdes_get_group_reg, lchip, grp, addr, mask, p_data);
    return CTC_E_NONE;
}

/*
[Func desc]        Get debug info
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint32 dbg_in: debug input parameter
[OUT param]        uint32* dbg_out: debug output parameter
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_dbg_info(uint8 lchip, uint16 serdes, uint32 dbg_in, uint32* dbg_out)
{
    MCHIP_SERDES_CB(serdes_dbg_info, lchip, serdes, dbg_in, dbg_out);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane precode
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
[CTC API]          CTC_CHIP_PROP_SERDES_PRE_CODING
*/
int32 sys_usw_dmps_serdes_get_lane_precode(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_en)
{
    MCHIP_SERDES_CB(serdes_get_lane_precode, lchip, serdes, dir, p_en);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane graycode
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_lane_graycode(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_en)
{
    MCHIP_SERDES_CB(serdes_get_lane_graycode, lchip, serdes, dir, p_en);
    return CTC_E_NONE;
}

/*
[Func desc]        Get lane MSB/LSB
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 dir: TX or RX, refers to sys_dmps_direction_t
[OUT param]        uint8* p_value: current msb or lsb, 1 or 0
[CTC API]          none
*/
int32 sys_usw_dmps_serdes_get_lane_msblsb(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_value)
{
    MCHIP_SERDES_CB(serdes_get_lane_msblsb, lchip, serdes, dir, p_value);
    return CTC_E_NONE;
}

/*
[Func desc]        Set optical mode
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
                   uint8 en: enable/disable, 1 - enable, 0 - disable
[OUT param]        None
[CTC API]          CTC_CHIP_PROP_SERDES_OPTICAl_MODE
*/
int32 sys_usw_dmps_serdes_set_rx_optical_mode(uint8 lchip, uint16 serdes, uint8 en)
{
    MCHIP_SERDES_CB(serdes_set_rx_optical_mode, lchip, serdes, en);
    return CTC_E_NONE;
}

/*
[Func desc]        Get optical mode
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        uint8* p_en: enable/disable, 1 - enable, 0 - disable
[CTC API]          CTC_CHIP_PROP_SERDES_OPTICAl_MODE
*/
int32 sys_usw_dmps_serdes_get_rx_optical_mode(uint8 lchip, uint16 serdes, uint8* p_en)
{
    MCHIP_SERDES_CB(serdes_get_rx_optical_mode, lchip, serdes, p_en);
    return CTC_E_NONE;
}

/*
[Func desc]        Get mapped gport and other lanes
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        void* p_lane_port: refer to ctc_port_serdes_info_t.
[CTC API]          CTC_CHIP_PROP_SERDES_ID_TO_GPORT
*/
int32 sys_usw_dmps_serdes_get_lane_port_info(uint8 lchip, uint16 serdes, void* p_lane_port)
{
    MCHIP_SERDES_CB(serdes_get_lane_port_info, lchip, serdes, p_lane_port);
    return CTC_E_NONE;
}

/*
[Func desc]        Dump SerDes Info
[IN param]         uint8 lchip: Lchip ID
                   uint16 serdes: physical user serdes ID
[OUT param]        
[CTC API]          CTC_CHIP_PROP_SERDES_ID_TO_GPORT
*/
int32 sys_usw_dmps_serdes_dump(uint8 lchip, uint16 serdes)
{
    MCHIP_SERDES_CB(serdes_dump, lchip, serdes);  
    return CTC_E_NONE;
}



int32 sys_usw_dmps_serdes_api_set_property_prbs(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_prbs_t* p_prbs = (ctc_chip_serdes_prbs_t*) p_value;
    uint16 serdes_id    = p_prbs->serdes_id;
    uint16 duration_ms  = 1000;
    uint8 dir           = p_prbs->mode;
    uint8 polynome      = p_prbs->polynome_type;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_set_lane_prbs_test_pattern(lchip, serdes_id, dir, polynome));

    if(DMPS_RX == dir)
    {
        CTC_ERROR_RETURN(sys_usw_dmps_serdes_set_lane_prbs_test_run(lchip, serdes_id, duration_ms, p_value));
    }

    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_set_property_ffe(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_ffe_t* p_ffe = (ctc_chip_serdes_ffe_t*) p_value;
    uint16 serdes_id    = p_ffe->serdes_id;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_set_tx_eq_force(lchip, serdes_id, p_value));
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_set_property_polarity(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_polarity_t* p_polarity = (ctc_chip_serdes_polarity_t*) p_value;
    uint16 serdes_id        = p_polarity->serdes_id;
    uint8  dir              = p_polarity->dir;
    uint8  polarity_mode    = (uint8)p_polarity->polarity_mode;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_set_lane_polarity(lchip, serdes_id, dir, polarity_mode));
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_set_property_loopback(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_loopback_t* p_loopback = (ctc_chip_serdes_loopback_t*) p_value;
    uint16 serdes_id = p_loopback->serdes_id;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_set_lane_loopback(lchip, serdes_id, p_value));
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_set_property_dfe(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_cfg_t* p_dfe = (ctc_chip_serdes_cfg_t*) p_value;
    uint16 serdes_id = p_dfe->serdes_id;
    uint8  en        = (uint8)p_dfe->value;   

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_set_rx_dfe_en(lchip, serdes_id, en));
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_set_property_ctle(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_ctle_t* p_ctle = (ctc_chip_serdes_ctle_t*) p_value;
    uint16 serdes_id = p_ctle->serdes_id;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_set_rx_ctle_force(lchip, serdes_id, p_value));
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_set_property_lane_en(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_cfg_t* p_cfg = (ctc_chip_serdes_cfg_t*) p_value;
    uint16 serdes_id = p_cfg->serdes_id;
    uint8  dir       = p_cfg->dir;
    uint8  en        = (uint8)p_cfg->value;   

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_set_lane_en(lchip, serdes_id, dir, en));
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_set_property(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    CTC_PTR_VALID_CHECK(p_value);

    switch (chip_prop)
    {
        case CTC_CHIP_PROP_SERDES_PRBS:
            //TODO: duration_ms
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_set_property_prbs(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_FFE:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_set_property_ffe(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PEOP_SERDES_POLARITY:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_set_property_polarity(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_LOOPBACK:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_set_property_loopback(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_P_FLAG:
        case CTC_CHIP_PROP_SERDES_PEAK:
        case CTC_CHIP_PROP_SERDES_DPC:
        case CTC_CHIP_PROP_SERDES_SLEW_RATE:
        case CTC_CHIP_PROP_SERDES_OPTICAl_MODE:
        case CTC_CHIP_PROP_SERDES_PRE_CODING:
            SYS_DATAPATH_DBG_OUT(CTC_DEBUG_LEVEL_DUMP, "%s, %d\n", __FUNCTION__, __LINE__);
            return CTC_E_NOT_SUPPORT;
        case CTC_CHIP_PROP_SERDES_DFE:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_set_property_dfe(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_CTLE:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_set_property_ctle(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_MAP:
            //TODO
            break;
        case CTC_CHIP_PROP_SERDES_EN:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_set_property_lane_en(lchip, chip_prop, p_value));
            break;
        default:
            return CTC_E_INVALID_PARAM;
    }

    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property_prbs(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_prbs_t* p_prbs = (ctc_chip_serdes_prbs_t*) p_value;
    uint16 serdes_id     = p_prbs->serdes_id;
    uint8  dir           = p_prbs->mode;
    uint8  polynome      = 0;
    uint32 duration_ms   = 1000;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_lane_prbs_test_pattern(lchip, serdes_id, dir, &polynome));

    if(DMPS_RX == dir)
    {
        CTC_ERROR_RETURN(sys_usw_dmps_serdes_set_lane_prbs_test_run(lchip, serdes_id, duration_ms, p_value));
    }
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property_ffe(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_ffe_t* p_ffe = (ctc_chip_serdes_ffe_t*) p_value;
    uint16 serdes_id    = p_ffe->serdes_id;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_tx_eq(lchip, serdes_id, p_value));
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property_polarity(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_polarity_t* p_polarity = (ctc_chip_serdes_polarity_t*) p_value;
    uint16 serdes_id        = p_polarity->serdes_id;
    uint8  dir              = p_polarity->dir;
    uint8  polarity_mode    = 0;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_lane_polarity(lchip, serdes_id, dir, &polarity_mode));

    p_polarity->polarity_mode = polarity_mode;
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property_loopback(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_loopback_t* p_loopback = (ctc_chip_serdes_loopback_t*) p_value;
    uint16 serdes_id        = p_loopback->serdes_id;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_lane_loopback(lchip, serdes_id, p_value));
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property_dfe(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_cfg_t* p_dfe = (ctc_chip_serdes_cfg_t*) p_value;
    uint16 serdes_id = p_dfe->serdes_id;
    uint8  en        = 0;   

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_rx_dfe_en(lchip, serdes_id, &en));

    p_dfe->value = en;
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property_ctle(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_ctle_t* p_ctle = (ctc_chip_serdes_ctle_t*) p_value;
    uint16 serdes_id = p_ctle->serdes_id;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_rx_ctle(lchip, serdes_id, p_value));
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property_lane_en(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_cfg_t* p_cfg = (ctc_chip_serdes_cfg_t*) p_value;
    uint16 serdes_id = p_cfg->serdes_id;
    uint8  dir       = p_cfg->dir;
    uint8  en        = 0;   

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_lane_en(lchip, serdes_id, dir, &en));

    p_cfg->value = en;
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property_pll_lock(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_pll_lock_status_t* p_pll_lock = (ctc_chip_pll_lock_status_t*) p_value;
    uint16 serdes_id = p_pll_lock->serdes_id;
    uint8 lock       = 0;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_lane_pll_lock(lchip, serdes_id, DMPS_TX, &lock));

    p_pll_lock->status = lock;

    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property_eye_diagram(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_chip_serdes_eye_diagram_t* p_eye = (ctc_chip_serdes_eye_diagram_t*) p_value;
    uint16 serdes_id    = p_eye->serdes_id;
    uint32 eye_height   = 0;
    uint32 eye_width    = 0;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_rx_eye_open(lchip, serdes_id, DMPS_SERDES_EYE_HEIGHT, &eye_height)); 
    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_rx_eye_open(lchip, serdes_id, DMPS_SERDES_EYE_WIDTH, &eye_width)); 

    p_eye->height = eye_height;
    p_eye->width  = eye_width;
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property_port_info(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    ctc_port_serdes_info_t* p_info = (ctc_port_serdes_info_t*) p_value;
    uint16 serdes_id    = p_info->serdes_id;

    CTC_ERROR_RETURN(sys_usw_dmps_serdes_get_lane_port_info(lchip, serdes_id, p_value));
    
    return CTC_E_NONE;
}

int32 sys_usw_dmps_serdes_api_get_property(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value)
{
    
    CTC_PTR_VALID_CHECK(p_value);

    switch (chip_prop)
    {
        case CTC_CHIP_PROP_SERDES_FFE:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_get_property_ffe(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PEOP_SERDES_POLARITY:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_get_property_polarity(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_LOOPBACK:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_get_property_loopback(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_P_FLAG:
        case CTC_CHIP_PROP_SERDES_PEAK:
        case CTC_CHIP_PROP_SERDES_DPC:
        case CTC_CHIP_PROP_SERDES_SLEW_RATE:
        case CTC_CHIP_PROP_SERDES_MAP:
        case CTC_CHIP_PROP_SERDES_OPTICAl_MODE:
        case CTC_CHIP_PROP_SERDES_PRE_CODING:
            SYS_DATAPATH_DBG_OUT(CTC_DEBUG_LEVEL_DUMP, "%s, %d\n", __FUNCTION__, __LINE__);
            return CTC_E_NOT_SUPPORT;
        case CTC_CHIP_PROP_SERDES_DFE:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_get_property_dfe(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_CTLE:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_get_property_ctle(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_EYE_DIAGRAM:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_get_property_eye_diagram(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_PRBS:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_get_property_prbs(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_PLL_LOCK_STATUS:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_get_property_pll_lock(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_ID_TO_GPORT:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_get_property_port_info(lchip, chip_prop, p_value));
            break;
        case CTC_CHIP_PROP_SERDES_EN:
            CTC_ERROR_RETURN(sys_usw_dmps_serdes_api_get_property_lane_en(lchip, chip_prop, p_value));
            break;
        default:
            return CTC_E_INVALID_PARAM;            
    }
    return CTC_E_NONE;
}


